<template>
  <div class="student">
    <h2>学生姓名:{{ name }}</h2>
    <h2>学生性别:{{ sex }}</h2>
    <button @click="sendStudentName">点我把学生名给App</button>
    <button @click="unbind">解绑atguigu事件</button>
    <button @click="death">销毁当前Student组件的实例(vc)</button>
  </div>
</template>

<script>
export default {
  name: "School",
  data() {
    return {
      name: '张三',
      sex: '男'
    }
  },
  methods: {
    sendStudentName() {
      //触发Student组件实例身上的atguigu事件
      this.$emit('atguigu', this.name)
    },
    unbind() {
      this.$off('atguigu')
    },
    death() {
      this.$destroy() //销毁了当前的student组件实例, 销毁后, 所以Student实例的自定义事件全部不奏效
    }

  }


}
</script>

<style scoped>
.student {
  background-color: pink;
  padding: 5px;
}
</style>